﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RayDen.Library.Components.Surface;
using RayDen.Library.Components.Surface.Measured;
using RayDen.Library.Components.SystemComponents;
using RayDen.Library.Core.Primitives;
using RayDen.Library.Data;
using RayDen.Library.Entity.Scene;

namespace RayDen.RayEngine.Scene
{
    public partial class FrameMaterialBuilder
    {

        public static void OverrideTextures(OptimizedTextureAtlas atlas,Dictionary<TextureType, int>[] texMaps)
        {
            var id = atlas.AddTexture(new SolidTextureInfo() { Name = "noise"});
            
        }

        public static void InitOverrides()
        {
            overrides = new Dictionary<string, Func<MaterialInfo, SurfaceMaterial>>(StringComparer.InvariantCultureIgnoreCase);
            overrides.Add("MatteMirror", materialInfo =>
                {


                  //  return new SurfaceMaterial(
                  //  //    new BrdfToBtdf(
                  //new MatteMaterial(materialInfo.DiffuseReflectance) { MaterialData = materialInfo } ,

                  //new AlloyMaterial(materialInfo.DiffuseReflectance, materialInfo.GlossReflectance, materialInfo.PhongExponent, 0.3f, false){ MaterialData = materialInfo }

                  //)
                  ////)

                  //  {
                        
                  //      Type = BrdfType.Diffuse,
                  //      Name = materialInfo.Name.ToLower(),                        
                  //  };

                    return new SurfaceMaterial(
                        //new GlassMaterial(materialInfo.GlossReflectance, materialInfo.DiffuseReflectance + 0.1f, 1.0005f, 1.5f, true, true)
                        //new AnisotropicPhong(materialInfo.DiffuseReflectance, materialInfo.GlossReflectance , 20f, 10f)
                        //new PhongMaterial(materialInfo.Kd, materialInfo.Ks, materialInfo.PhongExponent)
                        //new FresnelBlend(materialInfo.Kd, materialInfo.Ks, materialInfo.PhongExponent)
                        //new MatteMaterial(materialInfo.DiffuseReflectance)
                        //new OrenNayarMaterial(materialInfo.DiffuseReflectance, materialInfo.Kd.Filter())
                        //new MatteMaterial(materialInfo.DiffuseReflectance) 
                        //new MatteMirrorMaterial( materialInfo.DiffuseReflectance, materialInfo.GlossReflectance, true)
                        //new MirrorMaterial(materialInfo.DiffuseReflectance,true)
                        //new DistributionBsdf(materialInfo.PhongExponent, materialInfo.Kd)
                        //new DistributionBsdf(materialInfo.PhongExponent, materialInfo.Kd + 0.5f,new FresnelConductor(new RgbSpectrum(0.5f), new RgbSpectrum(0.025f)))
                        //new ArchGlassMaterial(materialInfo.Kd, materialInfo.Ks, true, true) { MaterialData = materialInfo }
                        //new AlloyMaterial(materialInfo.Kd, materialInfo.Ks, materialInfo.Exponent, 0.5f, true)

                        //new MetalMaterial(materialInfo.Kd, materialInfo.Exponent, true) { MaterialData = materialInfo }
                            new BrdfToBtdf(
                                new MatteMaterial(materialInfo.Kd) { MaterialData = materialInfo }
                            )
                        )
                    {
                        Name = materialInfo.Name,
                        Type = BrdfType.Diffuse,

                    };

                });
            overrides.Add("Alloy", materialInfo =>
            {

                //return new SurfaceMaterial(
                //    new BrdfToBtdf<MatteMaterial>(new MatteMaterial(materialInfo.DiffuseReflectance) {  MaterialData = materialInfo })
                //    )
                //{
                //    Type = BrdfType.Diffuse | BrdfType.Refractive,
                //    Name = materialInfo.Name.ToLower(),
                //};

                return new SurfaceMaterial(
                        new BrdfToBtdf(

                    new MatteMirrorMaterial(materialInfo.DiffuseReflectance, materialInfo.GlossReflectance, false)
                    {
                        MaterialData = materialInfo
                    })
                    )
                    /*
                    new MetalMaterial(materialInfo.GlossReflectance, 50f, false)
                    {
                        MaterialData = materialInfo
                    })*/

                {
                    Name = materialInfo.Name.ToLower(),
                    Type = BrdfType.Glossy
                };
            });
            /*

                    return new SurfaceMaterial(
                            new AlloyMaterial(materialInfo.DiffuseReflectance, materialInfo.GlossReflectance, materialInfo.PhongExponent, 0.1f, false)
                            {
                                MaterialData = materialInfo
                            }) { Name = materialInfo.Name.ToLower(), Type = BrdfType.Glossy };


                     return new SurfaceMaterial(
                        new RegularHalfangleBRDF(materialInfo.DataFile ?? @"F:\3D\Brdfs\merl\two-layer-silver.binary") { MaterialData = materialInfo })
                            {

                                Name = materialInfo.Name.ToLower(),
                                Type = BrdfType.Glossy,
                       
                            }; */

        }
    };
}

